package cn.aposoft.mq.kafka.admin.topic;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.DescribeReplicaLogDirsResult;
import org.apache.kafka.clients.admin.LogDirDescription;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.TopicPartitionReplica;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

public class DescribeReplicaLogDirs {
    public static void main(String[] args) {
        Properties p = new Properties();
        // kafka地址，多个地址用逗号分割
        p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "aposoft.cn:10091,aposoft.cn:10092,aposoft.cn:10093");
        try (Admin admin = Admin.create(p)) {
            Collection<TopicPartitionReplica> replicas =
                    Collections.singleton(new TopicPartitionReplica("test-new", 0, 92));
            DescribeReplicaLogDirsResult result = admin.describeReplicaLogDirs(replicas);
            KafkaFuture<Map<TopicPartitionReplica, DescribeReplicaLogDirsResult.ReplicaLogDirInfo>> future = result.all();
            Map<TopicPartitionReplica, DescribeReplicaLogDirsResult.ReplicaLogDirInfo> r = future.get();
            System.out.println(r);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
